﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPMS.Log
{
    /// <summary>
    /// 默认的日志错误处理器
    /// </summary>
    /// <remarks>用于提供默认的日志错误处理</remarks>
    /// <history>
    /// [zanezeng]               2009/9/25 15:39    创建
    /// </history>
    internal class DefaultLogErrorHandler : ILogErrorHandler
    {
        #region ---Constructor

        /// <summary>
        /// 初始化类型<see cref="DefaultLogErrorHandler"/>的新实例
        /// </summary>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:42    创建
        /// </history>
        private DefaultLogErrorHandler()
        {
        }

        #endregion

        #region ---ILogErrorHandler

        /// <summary>
        /// 处理给定信息描述的错误
        /// </summary>
        /// <param name="message">错误的描述信息</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:31    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:40    创建
        /// </history>
        public void HandleError( string message )
        {
            //输出日志
            if (LoggingContext.MetaLog.IsErrorEnabled)
            {
                LoggingContext.MetaLog.Error( message );
            }
        }

        /// <summary>
        /// 处理给定异常对象描述的错误
        /// </summary>
        /// <param name="ex">用于描述错误信息的异常对象</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:32    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:40    创建
        /// </history>
        public void HandleError( Exception ex )
        {
            //输出日志
            if (LoggingContext.MetaLog.IsErrorEnabled)
            {
                LoggingContext.MetaLog.Error( ex, string.Empty );
            }
        }

        /// <summary>
        /// 处理给定信息和异常对象描述的错误信息
        /// </summary>
        /// <param name="message">错误的描述信息</param>
        /// <param name="ex">用于描述错误信息的异常对象</param>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:32    创建
        /// </history>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:41    创建
        /// </history>
        public void HandleError( string message, Exception ex )
        {
            //输出日志
            if (LoggingContext.MetaLog.IsErrorEnabled)
            {
                LoggingContext.MetaLog.Error( ex, message );
            }
        }

        #endregion

        #region ---Property

        /// <summary>
        /// 获得默认的日志错误处理器实例
        /// </summary>
        /// <value>默认的日志错误处理器实例</value>
        /// <remarks></remarks>
        /// <history>
        /// [zanezeng]               2009/9/25 15:41    创建
        /// </history>
        public static ILogErrorHandler Default
        {
            get
            {
                return DEFAULT_ERRORHANDLER;
            }
        }

        #endregion

        #region ---Field

        /// <summary>
        /// 默认的日志错误处理器实例
        /// </summary>
        private static readonly ILogErrorHandler DEFAULT_ERRORHANDLER = new DefaultLogErrorHandler();

        #endregion
    }
}
